package org.umss.fixturebuilder.resources;

import java.util.List;
import javax.ws.rs.Consumes;
import javax.ws.rs.GET;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
import org.umss.fixturebuilder.controller.ChampionshipController;
import org.umss.fixturebuilder.model.json.JsonChampionshipList;
import org.umss.fixturebuilder.model.json.JsonNewChampionship;

/**
 *
 * @author Daniela Meneses
 */
@Path("championship")
public class ChampionshipResource {

    @GET
    @Path("/all")
    @Produces(MediaType.APPLICATION_JSON)
    public Response getAll() {

        List<String> championships = ChampionshipController.getAll();
        JsonChampionshipList list = new JsonChampionshipList(championships);

        return championships != null ? Response.status(Response.Status.OK).entity(list).build()
                : Response.status(Response.Status.INTERNAL_SERVER_ERROR).build();
    }

    @POST
    @Consumes(MediaType.APPLICATION_JSON)
    public Response create(JsonNewChampionship championship) {

        boolean created = ChampionshipController.create(championship);

        return created ? Response.status(Response.Status.CREATED).build()
                : Response.status(Response.Status.INTERNAL_SERVER_ERROR).build();
    }
}
